package com.dianshang.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dianshang.dao.CategoryReportDao;
import com.dianshang.pojo.order.CategoryReport;
import com.dianshang.service.order.CategoryReportService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Service
public class CategoryReportServiceImpl implements CategoryReportService {

    @Autowired
    private CategoryReportDao categoryReportDao;

    /**
     * 昨天的数据统计(商品类目)
     */
    @Override
    public List<CategoryReport> getCategory(LocalDate localDate) {
        return categoryReportDao.getCategory(localDate);
    }

    /**
     * 按日期统计一级分类数据总和
     */
    @Override
    public List<Map> categoryCount(String date1, String date2) {
        return categoryReportDao.categoryCount(date1,date2);
    }

    @Override
    public void createData() {
        /**
         * 昨天的数据统计(商品类目)
         */
        LocalDate localDate=LocalDate.now().minusDays(1);
        List<CategoryReport> categoryReports = categoryReportDao.getCategory(localDate);

        /**
         * 保存到tb_category_report
         */
        for(CategoryReport categoryReport:categoryReports){
            categoryReportDao.insert(categoryReport);
        }
    }

}